#include <bits/stdc++.h>
#define int unsigned long long // 一定要开 unsigned long long
using namespace std;
int sum[2050][2050], temp, n, m, q, ans;
int u, v, x, y;
signed main()
{
    int t;
    cin >> t;
    while (t--)
    {
        ans = 0; // 多测不清空，爆零两行泪
        cin >> n >> m >> q;
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= m; j++)
            {
                cin >> temp;
                sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + temp;
            } // O(nm)预处理
        for (int i = 1; i <= q; i++)
        {
            cin >> u >> v >> x >> y;
            ans ^= sum[x][y] + sum[u - 1][v - 1] - sum[u - 1][y] - sum[x][v - 1]; // O(1)查询
        } // 异或处理答案，不取模是因为 unsigned long long 会自然溢出
        cout << ans << endl; // 记得换行
    }
    return 0;
}